//
//  LZBasePresenter.m
//  laziz_Consumer
//
//  Created by XMac on 16/12/12.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZBasePresenter.h"
#import "LZRemindView.h"
#import "LZAlertView.h"
#import "AppDelegate.h"
#import "LZUserModel.h"

@implementation LZBasePresenter

+ (BOOL)isRequestStatusCodeCorrect:(id)data fail:(PresenterCommonFail)fail {
    if ([data[@"statusCode"] integerValue] == kCodeSuccesss) {
        return YES;
    }
    else if ([data[@"statusCode"] isEqualToString:@"0400034"]) {
        
        AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
        
        LZAlertView *alert = [[LZAlertView alloc] initWithContent:LZLocalizedString(@"mag_account_stopstate", nil)
                                                         andImage:nil
                                                cancelButtonTitle:LZLocalizedString(@"cancel", nil)
                                                otherButtonTitles:nil, nil];
        [alert show];
        
        alert.clickButtonIndexBlock = ^(NSInteger index){
            [[LZUserModel Instance] logOut];
            [appDelegate setRootForLoginVCWithIsShowLeadingView:NO];
        };

        return NO;
    }
    else {
        DLog(@"接口请求失败：\n%@",data);
        NSString *errorCode = data[@"statusCode"];
        DLog(@"errorCode:%@", errorCode);
        fail(errorCode);
        return NO;
    }
}

+ (BOOL)isRequestStatusCode:(id)data fail:(PresenterCommonFail)fail {

    if ([data[@"statusCode"] integerValue] == kCodeSuccesss) {
        return YES;
    }
    else {
        //        NSString *str = data[@"errorData"];
        DLog(@"接口请求失败：\n%@",data);
        NSString *errorCode = data[@"statusCode"];
        DLog(@"errorCode:%@", errorCode);
        fail(errorCode);
        return NO;
    }
}

@end
